package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yl.auth.entity.Renwushezhi;
import com.yl.auth.service.RenwushezhiService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author W
 * @since 2023-07-07
 */
@RestController
@RequestMapping("/admin/auth/renwushezhi")
@Api(tags = "市场销售-任务设置")
public class RenwushezhiController {

    @Resource
    private RenwushezhiService renwushezhiService;

    @ApiOperation(value = "新增任务")
    @PostMapping("/xinrenwu/{time}/{id}")
    public Result xinrenwu(@RequestBody Renwushezhi renwushezhi, @PathVariable Integer time, @PathVariable Long
                           id){
        renwushezhi.setLaorenId(id);
        renwushezhi.setTime(time);
        renwushezhiService.save(renwushezhi);
        return Result.ok();
    }

    @ApiOperation(value = "修改任务")
    @PutMapping("/xiurenwu")
    public Result xiurenwu(@RequestBody Renwushezhi renwushezhi) {
        renwushezhiService.updateById(renwushezhi);
        return Result.ok();
    }

    @ApiOperation(value = "根据状态进行回显")
    @GetMapping("/huixian/{id}")
    public Result huixian(@PathVariable Long id) {
        //使用条件构造器进行查询和任务设置中老人的外键是否一致
        LambdaQueryWrapper<Renwushezhi> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Renwushezhi::getLaorenId,id);
        //返回一致的老人的信息
        List<Renwushezhi> list = renwushezhiService.list(wrapper);
        return Result.ok(list);
    }
    @ApiOperation(value = "日循环新增任务")
    @GetMapping("/xiuGai/{time}/{id}")
    public Result xiuGai(@PathVariable Integer time,@PathVariable Long id){
        Renwushezhi renwushezhi = renwushezhiService.getTime(time,id);
        return Result.ok(renwushezhi);
    }

    @ApiOperation(value = "周循环新增任务")
    @PostMapping("/zhouxunXinRenwu/{time}/{week}/{laorenId}")
    public Result yuexunXinRenwu(@RequestBody Renwushezhi renwushezhi,@PathVariable Integer time,
                                 @PathVariable Integer week,@PathVariable Long laorenId){
        renwushezhi.setTime(time);
        renwushezhi.setWeek(week);
        renwushezhi.setLaorenId(laorenId);
        renwushezhiService.save(renwushezhi);
        return Result.ok();
    }

    @ApiOperation(value = "月循环新增任务")
    @PostMapping("/yueXinRenWu/{time}/{month}/{laorenId}")
    public Result yueXinRenWu(@RequestBody Renwushezhi renwushezhi,@PathVariable Integer time,
                              @PathVariable Integer month,@PathVariable Long laorenId){
        renwushezhi.setTime(time);
        renwushezhi.setLaorenId(laorenId);
        renwushezhi.setMonth(month);
        renwushezhiService.save(renwushezhi);
        return Result.ok();
    }
}

